package cn.tedu.basic;

import javax.xml.bind.SchemaOutputResolver;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class PracticeJdbc {
    public static void main(String[] args) throws Exception {
        method();
    }

    private static void method() throws Exception {
//        1.注册驱动jar包
        Class.forName("com.mysql.jdbc.Driver");
//        2.连接数据库
        Connection con = DriverManager.getConnection("jdbc:mysql:///jdbctest", "root", "root");
//        3.获取传输器
        Statement st = con.createStatement();
//        4.执行SQL
        String sql="select * from user";
        ResultSet rs = st.executeQuery(sql);
//        5.解析结果集
        while(rs.next()){
            String id = rs.getString(1);
            System.out.println(id);
        }
//        6.释放资源
        con.close();
        st.close();
        rs.close();
    }
}
